package org.dtrd.modules.archive.entity.bean.report;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveComorbidity;

import java.util.StringJoiner;

/**
 * @author qr
 * @date 2022/1/20 21:47
 */
@ApiModel("糖尿病合并症报告")
@Getter
@Setter
public class DiabetesComorbidityReport {

    @ApiModelProperty("高血压病")
    private String hypertensionText;
    @ApiModelProperty("高血压确诊日期")
    private String hypertensionDate = Constant.PLACEHOLDER;
    @ApiModelProperty("高血压病数据")
    private String hypertensionData = Constant.PLACEHOLDER;

    @ApiModelProperty("是否有高血脂")
    private String hyperlipidemiaText;
    @ApiModelProperty("高甘油三酯血症确诊日期")
    private String hypertriglyceridemiaDate = Constant.PLACEHOLDER;
    @ApiModelProperty("是否服用降脂药1")
    private String ifHypolipidemic1 = Constant.PLACEHOLDER;
    @ApiModelProperty("高胆固醇血症确诊日期")
    private String hypercholesterolemiaDate = Constant.PLACEHOLDER;
    @ApiModelProperty("是否服用降脂药2")
    private String ifHypolipidemic2 = Constant.PLACEHOLDER;

    @ApiModelProperty("是否有心血管疾病")
    private String angiocardiopathyText;
    @ApiModelProperty("心血管疾病确诊日期")
    private String angiocardiopathyDate = Constant.PLACEHOLDER;
    @ApiModelProperty("心血管疾病相关检查")
    private String angiocardiopathyExam = Constant.PLACEHOLDER;

    @ApiModelProperty("是否有脑血管疾病")
    private String cerebrovascularText;
    @ApiModelProperty("脑卒中类型")
    private String strokeType = Constant.PLACEHOLDER;
    @ApiModelProperty("脑卒中其他描述")
    private String strokeOther = Constant.PLACEHOLDER;
    @ApiModelProperty("脑卒中确诊日期")
    private String strokeDate = Constant.PLACEHOLDER;
    @ApiModelProperty("急性脑缺血确诊日期")
    private String ischemiaDate = Constant.PLACEHOLDER;
    @ApiModelProperty("短暂性脑缺血发作确诊日期")
    private String transientIschemiaDate = Constant.PLACEHOLDER;
    @ApiModelProperty("动脉粥样硬化性CCVD确诊日期")
    private String ccvdDate = Constant.PLACEHOLDER;
    @ApiModelProperty("其他脑血管疾病")
    private String cerebrovascularOther = Constant.PLACEHOLDER;
    @ApiModelProperty("脑血管疾病相关检查")
    private String cerebrovascularCheck = Constant.PLACEHOLDER;

    @ApiModelProperty("是否有周围血管疾病")
    private String peripheralText;
    @ApiModelProperty("外周动脉疾病确诊日期")
    private String arteryDate = Constant.PLACEHOLDER;
    @ApiModelProperty("动脉瘤确诊日期")
    private String aneurysmDate = Constant.PLACEHOLDER;
    @ApiModelProperty("动静脉瘘确诊日期")
    private String fistulaDate = Constant.PLACEHOLDER;
    @ApiModelProperty("外周静脉疾病确诊日期")
    private String venousDate = Constant.PLACEHOLDER;
    @ApiModelProperty("周围血管损伤确诊日期")
    private String injuryDate = Constant.PLACEHOLDER;
    @ApiModelProperty("周围血管疾病类型")
    private String peripheralType;

    public DiabetesComorbidityReport parseFromPo(DtrdEntRdArchiveComorbidity po) {
        // 高血脂
        Integer hyperlipidemia = po.getHyperlipidemia();
        if (hyperlipidemia != null && hyperlipidemia.equals(Constant.DiabetesDiagnose.DIAGNOSE.getType())) {
            hyperlipidemiaText = Constant.DiabetesDiagnose.DIAGNOSE.getName();
            if (po.getHypertriglyceridemiaDate() != null) {
                hypertriglyceridemiaDate = DateUtil.formatDate(po.getHypertriglyceridemiaDate());
            }
            ifHypolipidemic1 = "是否服用降脂药物: " + Constant.YesOrNo.valueOf(po.getIfHypolipidemic1()).getName();
            if (po.getHypercholesterolemiaDate() != null) {
                hypercholesterolemiaDate = DateUtil.formatDate(po.getHypercholesterolemiaDate());
            }
            ifHypolipidemic2 = "是否服用降脂药物: " + Constant.YesOrNo.valueOf(po.getIfHypolipidemic2()).getName();
        }
        // 脑血管疾病
        Integer cerebrovascular = po.getCerebrovascular();
        if (cerebrovascular != null && cerebrovascular.equals(Constant.DiabetesDiagnose.DIAGNOSE.getType())) {
            cerebrovascularText = Constant.DiabetesDiagnose.DIAGNOSE.getName();
            if (po.getStrokeType() != null) {
                String type = Constant.CerebrovascularType.valueOf(po.getStrokeType()).getName();
                if (type.equals(Constant.other)) {
                    strokeType = po.getStrokeOther();
                }else {
                    strokeType = type;
                }
            }
            if (po.getStrokeDate() != null) {
                strokeDate = DateUtil.formatDate(po.getStrokeDate());
            }
            if (po.getIschemiaDate() != null) {
                ischemiaDate = DateUtil.formatDate(po.getIschemiaDate());
            }
            if (po.getTransientIschemiaDate() != null) {
                transientIschemiaDate = DateUtil.formatDate(po.getTransientIschemiaDate());
            }
            if (po.getCcvdDate() != null) {
                ccvdDate = DateUtil.formatDate(po.getCcvdDate());
            }
            cerebrovascularCheck = po.getCerebrovascularCheck();
            cerebrovascularOther = po.getCerebrovascularOther();
        }
        // 周围血管疾病
        Integer peripheral = po.getPeripheral();
        if (peripheral != null && peripheral.equals(Constant.DiabetesDiagnose.DIAGNOSE.getType())) {
            peripheralText = Constant.DiabetesDiagnose.DIAGNOSE.getName();
            if (po.getArteryDate() != null) {
                arteryDate = DateUtil.formatDate(po.getArteryDate());
            }
            if (po.getAneurysmDate() != null) {
                aneurysmDate = DateUtil.formatDate(po.getAneurysmDate());
            }
            if (po.getFistulaDate() != null) {
                fistulaDate = DateUtil.formatDate(po.getFistulaDate());
            }
            if (po.getVenousDate() != null) {
                venousDate = DateUtil.formatDate(po.getVenousDate());
            }
            if (po.getInjuryDate() != null) {
                injuryDate = DateUtil.formatDate(po.getInjuryDate());
            }
            if (po.getPeripheralType() != null) {
                String peripheralType = po.getPeripheralType();
                String[] strings = peripheralType.split(",");
                StringJoiner joiner = new StringJoiner("、");
                for (String s : strings) {
                    Constant.PeripheralType type = Constant.PeripheralType.valueOf(Integer.parseInt(s));
                    if (type != null) {
                        joiner.add(type.getName());
                    }
                }
                this.peripheralType = joiner.toString();
            }
        }
        return this;
    }
}
